
	function checkUserID()
	{
		var userID = document.getElementById("userid").value;
		if(userID=="")
		{alert("please enter the userid!");return false;}
		if(userID.length!=8)
		{alert("length of userid is invalid!");return false;}
		if(!/^\d+$/.test(userID))
		{alert("userid is invalid!");return false;}
		
		getUserInfoAjax(userID);
	}
	
	function getUserInfoAjax(userid)
	{
		var xmlHttp = null;
		if(window.ActiveXObject)
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else if(window.XMLHttpRequest)
		{
			xmlHttp = new XMLHttpRequest();
		}else
		{
			alert("Ajax won't show in your web browser ");
			return;
		}
		xmlHttp.open("GET", "BorrowDotServlet?option=check&userID=" + userid, true);
		xmlHttp.onreadystatechange = function()
		{
		    if(xmlHttp.readyState==4 && xmlHttp.status==200)
			{
		    	var login=/<script>/ig;
		    	if(login.test(xmlHttp.responseText))
		    	{
		    		eval("top.location.href='/lab/login.jsp'");
		    		return;
		    	}
				var type = xmlHttp.getResponseHeader("content-Type");
				
				if(type=="text/html")
				{
					var jsonStr = xmlHttp.responseText;
					document.getElementById("message").innerHTML = jsonStr;
					document.getElementById("firstname").value = "";
					document.getElementById("lastname").value =  "";
					document.getElementById("gender").value = "";
					document.getElementById("email").value = "";
					document.getElementById("context").value ="";
				}
				else if(type=="application/json")
				{
					var jsonObj = eval('('+xmlHttp.responseText+')');
					document.getElementById("userid").value = jsonObj.userID;
					document.getElementById("firstname").value = jsonObj.firstname;
					document.getElementById("lastname").value = jsonObj.lastname;
					document.getElementById("gender").value = jsonObj.gender;
					document.getElementById("email").value = jsonObj.email;
					document.getElementById("context").value = jsonObj.context;
					document.getElementById("message").innerHTML = "SUCCESS!";
				}
			}
			else
			{
				document.getElementById("message").innerHTML = "loading...";
			}
		}
		xmlHttp.send();
		
	}
	
	function checkUserID_Context()
	{
		var userID = document.getElementById("userid").value;
		if(userID=="")
		{alert("please enter the userid!");return false;}
		if(userID.length!=8)
		{alert("length of userid is invalid!");return false;}
		if(!/^\d+$/.test(userID))
		{alert("userid is invalid!");return false;}
		var context = document.getElementById("context").value; 
		updateDotAjax(userID,context);
	}
	function updateDotAjax(userID,context)
	{
		var xmlHttp = null;
		var xmlDoc = null;
		if(window.ActiveXObject)
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else if(window.XMLHttpRequest)
		{
			xmlHttp = new XMLHttpRequest();
		}
		xmlHttp.open("POST", "BorrowDotServlet", true);
		xmlHttp.onreadystatechange = function()
		{
			
			if(xmlHttp.readyState==4 && xmlHttp.status==200)
			{
				var login=/<script>/ig;
				if(login.test(xmlHttp.responseText))
				{
					eval("top.location.href='/lab/login.jsp'");
					return;
				}
				document.getElementById("message").innerHTML = xmlHttp.responseText;
			}
			else
			{
				document.getElementById("message").innerHTML = "uploading...";
			}
		}
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.send("option=submit&userID="+userID +"&context="+context);
	}